package tom.spring.cloud.integration.sender;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.InboundChannelAdapter;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.support.GenericMessage;

import java.util.Date;

/**
 * 使用source的output作为输出，向my-topic02发送消息
 * @author ZHUFEIFEI
 */
@Slf4j
@EnableBinding({Source.class})
public class Sender01 {

    /**
     * 每秒向指定topic发送时间信息
     * @return
     */
    @Bean
    @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedRate = "2000"))
    public MessageSource<Date> time() {
        Date dt = new Date();
        return () -> { log.info("output01 : {}", dt);return new GenericMessage<>(dt);};
    }

}
